package leecode

import (
	"sort"
)

func FindContentChildren(g []int, s []int) (result int) {
	sort.Ints(g)
	sort.Ints(s)
	if len(g) == 0 || len(s) == 0 {
		return
	}
	var gIndex int
	//循环遍历饼干
	for i := 0; i < len(s); i++ {
		if g[gIndex] > s[i] {
			continue
		}
		if g[gIndex] <= s[i] {
			result++
			gIndex++
		}
		if gIndex >= len(g) {
			return
		}
	}
	return
}
